package com.lzx.iteam;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.widget.*;
import com.lzx.iteam.adapter.WeeklyChooseYearMonthAdapter;
import com.lzx.iteam.adapter.WeeklyDetailListAdapter;
import com.lzx.iteam.base.FindViewById;
import com.lzx.iteam.base.MyBaseActivity;
import com.lzx.iteam.bean.AttendanceData;
import com.lzx.iteam.bean.WeeklyDataBean;
import com.lzx.iteam.bean.WeeklyDetailListData;
import com.lzx.iteam.emotion.EmotionUtil;
import com.lzx.iteam.net.*;
import com.lzx.iteam.provider.CloudDBOperation;
import com.lzx.iteam.util.AllDialogUtil;
import com.lzx.iteam.util.Constants;
import com.lzx.iteam.util.PreferenceUtil;
import com.lzx.iteam.util.StringUtil;
import com.lzx.iteam.widget.PinnedSectionListView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.*;

/**
 * Created by Megan on 16/5/24.
 */
public class WeeklyDetailListActivity extends MyBaseActivity implements View.OnClickListener, View.OnTouchListener {

    @FindViewById(id = R.id.ll_weekly_detail_list_back)
    private LinearLayout mLayoutBack;
    @FindViewById(id = R.id.tv_weekly_detail_list_title)
    private TextView mTvTitle;
    @FindViewById(id = R.id.ll_weekly_detail_list_filt_layout)
    private LinearLayout mLayoutFilt;
    @FindViewById(id = R.id.ll_weekly_detail_list_year)
    private LinearLayout mLayoutYear;
    @FindViewById(id = R.id.ll_weekly_detail_list_month)
    private LinearLayout mLayoutMonth;
    @FindViewById(id = R.id.lv_weekly_detail_list_list)
    private ListView mLvList;
    @FindViewById(id = R.id.weekly_detail_list_pop_bg)
    private ImageView mIvPopBg;
    @FindViewById(id = R.id.ll_weekly_detail_list_month_grid)
    private LinearLayout mLlMonth;
    @FindViewById(id = R.id.gv_weekly_detail_list_month_grid)
    private GridView mGvMonth;
    @FindViewById(id = R.id.tv_weekly_detail_list_month_clear)
    private TextView mTvMonthClear;
    @FindViewById(id = R.id.lv_weekly_detail_list_year_list)
    private ListView mLvYear;
    @FindViewById(id = R.id.tv_weekly_detail_list_month_text)
    private TextView mTvMonthText;
    @FindViewById(id = R.id.tv_weekly_detail_list_month)
    private TextView mTvMonth;
    @FindViewById(id = R.id.iv_weekly_detail_list_month_arrow)
    private ImageView mIvMonthArrow;
    @FindViewById(id = R.id.iv_weekly_detail_list_message)
    private ImageView mIvMessage;
    @FindViewById(id = R.id.tv_weekly_detail_list_year_text)
    private TextView mTvYearText;
    @FindViewById(id = R.id.tv_weekly_detail_list_year)
    private TextView mTvYear;
    @FindViewById(id = R.id.iv_weekly_detail_list_year_arrow)
    private ImageView mIvYearArrow;
    @FindViewById(id = R.id.ll_weekly_detail_list_bottom)
    private LinearLayout mLlBottomLayout;
    @FindViewById(id = R.id.et_weekly_detail_list_input)
    private EditText mEtCommentEdit;
    @FindViewById(id = R.id.iv_weekly_detail_list_emotion)
    private ImageView mIvEmotiom;
    @FindViewById(id = R.id.tv_weekly_detail_list_send)
    private TextView mTvSend;
    @FindViewById(id = R.id.tv_weekly_detail_list_red_dot)
    private TextView mRedDot;
    @FindViewById(id = R.id.ll_weekly_detail_list_emotion)
    private LinearLayout mEmotionLayout;
    @FindViewById(id = R.id.weekly_detail_list_emotion_viewpager)
    private ViewPager mVpEmotion;
    @FindViewById(id = R.id.weekly_detail_list_emotion_dots_container)
    private LinearLayout mLlEmotionDots;

    private int curYear;

    private int yearPostion = 2;
    private int monthPosition = -1;
    private String[] month = {"一月", "七月", "二月", "八月", "三月", "九月", "四月", "十月", "五月", "十一月", "六月", "十二月"};
    private String[] year;

    private String mSendMessage;
    private int mPosition;
    private String commentWeeklyId;

    private CloudDBOperation mCloudDBOperation;

    private WeeklyChooseYearMonthAdapter yearAdapter;
    private WeeklyChooseYearMonthAdapter monthAdapter;

    private WeeklyDetailListAdapter adapter;
    private EmotionUtil mEmotionUtil;
    private String mAction;
    private String mGroupId;
    private String mWeeklyIds;
    private int mUnReadCount;

    private AllDialogUtil mDialogUtil;
    private Dialog mProgressDialog;
    ArrayList<WeeklyDetailListData> dataBeans = new ArrayList<WeeklyDetailListData>();

    private final int GET_MY_WEEKLY_LIST = 10001;
    private final int ADD_COMMENT_MSG = 10002;
    private final int DELETE_WEEKLY_MSG = 10003;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case GET_MY_WEEKLY_LIST:
                    if (msg.arg1 == 0) {
                        dataBeans.clear();
                        dataBeans = (ArrayList<WeeklyDetailListData>) msg.obj;
                        adapter.bindData(dataBeans);
                        if ("weekly_list".equals(mAction)) {
                            mTvTitle.setText(getIntent().getStringExtra("title") + "(" + dataBeans.size() + ")");
                        }
                    } else {
                        Toast.makeText(mActivity, (String) msg.obj, Toast.LENGTH_LONG).show();
                    }
                    break;
                case ADD_COMMENT_MSG:
                    if (msg.arg1 == 0) {
                        ArrayList<String> nameCard = (ArrayList<String>) PreferenceUtil.getInstance(WeeklyDetailListActivity.this).getCloudContact(Constants.CONTACT_NAME_CARD);
                        Map<String, String> map = new HashMap<String, String>();
                        map.put(Constants.COMMENT_USER_ID, PreferenceUtil.getInstance(WeeklyDetailListActivity.this).getString(PreferenceUtil.CLIENT_USEID, "－1"));
                        if (nameCard != null && nameCard.size() > 0) {
                            map.put(Constants.COMMENT_USER_NAME, nameCard.get(0));
                        }
                        map.put(Constants.COMMENT_CREATE_TIME, System.currentTimeMillis() / 1000 + "");
                        map.put(Constants.COMMENT_CONTENT, mSendMessage);
                        if (dataBeans.get(mPosition).comments == null) {
                            ArrayList<Map<String, String>> comments = new ArrayList<Map<String, String>>();
                            comments.add(map);
                            dataBeans.get(mPosition).comments = comments;
                        } else {
                            dataBeans.get(mPosition).comments.add(map);
                        }
                        adapter.bindData(dataBeans);
                        //更新数据库
                        mLlBottomLayout.setVisibility(View.GONE);
                        mSendMessage = "";
                        mEtCommentEdit.requestFocus();
                        ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                        //   ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                    } else {
                        Toast.makeText(mActivity, (String) msg.obj, Toast.LENGTH_LONG).show();
                    }

                    break;
                case DELETE_WEEKLY_MSG:
                    if (msg.arg1 == 0) {
                        httpReqDlgDismiss();
                        dataBeans.remove(mPosition);
                        adapter.bindData(dataBeans);
                    } else {
                        Toast.makeText(mActivity, (String) msg.obj, Toast.LENGTH_LONG).show();
                    }
                    break;
            }

        }
    };

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, R.layout.weekly_detail_list_layout);

    }

    @Override
    public void initListener() {
        mLayoutBack.setOnClickListener(this);
        mTvMonthClear.setOnClickListener(this);
        mLayoutYear.setOnClickListener(this);
        mLayoutMonth.setOnClickListener(this);
        mIvMessage.setOnClickListener(this);
        mIvEmotiom.setOnClickListener(this);
        mEtCommentEdit.setOnClickListener(this);
        mTvSend.setOnClickListener(this);
        mEtCommentEdit.addTextChangedListener(mTextWatcher);

        mLvYear.setOnTouchListener(this);
        mLlMonth.setOnTouchListener(this);

        mLvYear.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                yearPostion = position;
                yearAdapter.setChooseYear(yearPostion);
                mLvYear.setVisibility(View.GONE);
                mTvYear.setText(year[position]);
                mTvYearText.setTextColor(getResources().getColor(R.color.schedule_content));
                mTvYear.setTextColor(getResources().getColor(R.color.schedule_content));
                mIvYearArrow.setImageResource(R.drawable.arrow_down1);
                getFilterWeekly();
            }
        });

        mGvMonth.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                monthPosition = position;
                monthAdapter.setChooseMonth(monthPosition);
                mLlMonth.setVisibility(View.GONE);
                mTvMonth.setText(month[position]);
                mTvMonthText.setTextColor(getResources().getColor(R.color.schedule_content));
                mTvMonth.setTextColor(getResources().getColor(R.color.schedule_content));
                mIvMonthArrow.setImageResource(R.drawable.arrow_down1);
                mLvList.setEnabled(true);
                getFilterWeekly();
            }
        });

    }

    @Override
    public void initData() {
        Calendar c = Calendar.getInstance();
        curYear = c.get(Calendar.YEAR);
        year = new String[3];
        year[0] = curYear + "年";
        year[1] = curYear - 1 + "年";
        year[2] = "不限";
        mEtCommentEdit.requestFocus();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        yearAdapter = new WeeklyChooseYearMonthAdapter(this, 0);
        yearAdapter.bindData(year);
        mLvYear.setAdapter(yearAdapter);

        monthAdapter = new WeeklyChooseYearMonthAdapter(this, 1);
        monthAdapter.bindData(month);
        mGvMonth.setAdapter(monthAdapter);

        mCloudDBOperation = new CloudDBOperation(this);
        initEmotion();
        mDialogUtil = new AllDialogUtil(this);

        Intent intent = getIntent();
        mAction = intent.getAction();
        mGroupId = intent.getStringExtra("groupId");
        mUnReadCount = intent.getIntExtra("unreadCount", 0);
        mWeeklyIds = intent.getStringExtra("weeklyIds");
        adapter = new WeeklyDetailListAdapter(this, mAction);
        mLvList.setAdapter(adapter);
        if ("my_weekly".equals(mAction)) {
            mLayoutFilt.setVisibility(View.VISIBLE);
            mIvMessage.setVisibility(View.VISIBLE);
            mRedDot.setVisibility(View.VISIBLE);
            getFilterWeekly();
            setNewMsg();
            getMyWeeklyList();
        } else if ("weekly_list".equals(mAction)) {
            mLayoutFilt.setVisibility(View.GONE);
            mIvMessage.setVisibility(View.GONE);
            mRedDot.setVisibility(View.GONE);
            mTvTitle.setText(intent.getStringExtra("title"));
            dataBeans.clear();
            dataBeans = mCloudDBOperation.findWeeklyDetailListData(-2, intent.getStringExtra("year"),intent.getStringExtra("month"), mAction, mGroupId,intent.getStringExtra("weekCount"));
            adapter.bindData(dataBeans);
            getNWeeklyList();
        }

    }

    private void initEmotion() {
        mEmotionUtil = new EmotionUtil(this, mEtCommentEdit, mLlEmotionDots, mVpEmotion);
        mEmotionUtil.initStaticFaces();
        mEmotionUtil.initViewPager();
        mVpEmotion.setOnPageChangeListener(mEmotionUtil.new PageChange());
    }


    @Override
    public void onClick(View view) {
        if (Constants.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.ll_weekly_detail_list_back:
                finish();
                break;
            case R.id.iv_weekly_detail_list_message:
                mUnReadCount = 0;
                setNewMsg();
                Intent intent = new Intent(this, WeeklyMsgActivity.class);
                intent.putExtra("groupId", mGroupId);
                startActivity(intent);
                break;
            case R.id.tv_weekly_detail_list_month_clear:
                monthPosition = -1;
                monthAdapter.setChooseMonth(monthPosition);
                mLlMonth.setVisibility(View.GONE);
                mTvMonth.setText("不限");
                mTvMonthText.setTextColor(getResources().getColor(R.color.schedule_content));
                mTvMonth.setTextColor(getResources().getColor(R.color.schedule_content));
                mIvMonthArrow.setImageResource(R.drawable.arrow_down1);
                mLvList.setEnabled(true);
                getFilterWeekly();
                break;
            case R.id.ll_weekly_detail_list_year:
                if (mLvYear.getVisibility() == View.VISIBLE) {
                    mLvYear.setVisibility(View.GONE);
                    mTvYearText.setTextColor(getResources().getColor(R.color.schedule_content));
                    mTvYear.setTextColor(getResources().getColor(R.color.schedule_content));
                    mIvYearArrow.setImageResource(R.drawable.arrow_down1);
                } else {
                    mLvYear.setVisibility(View.VISIBLE);
                    mTvYearText.setTextColor(getResources().getColor(R.color.event_btn_click));
                    mTvYear.setTextColor(getResources().getColor(R.color.event_btn_click));
                    mIvYearArrow.setImageResource(R.drawable.arrow_up1);
                }
                mLlMonth.setVisibility(View.GONE);
                mTvMonthText.setTextColor(getResources().getColor(R.color.schedule_content));
                mTvMonth.setTextColor(getResources().getColor(R.color.schedule_content));
                mIvMonthArrow.setImageResource(R.drawable.arrow_down1);
                mLvList.setEnabled(true);
                break;
            case R.id.ll_weekly_detail_list_month:
                if (mLlMonth.getVisibility() == View.VISIBLE) {
                    mLlMonth.setVisibility(View.GONE);
                    mTvMonthText.setTextColor(getResources().getColor(R.color.schedule_content));
                    mTvMonth.setTextColor(getResources().getColor(R.color.schedule_content));
                    mIvMonthArrow.setImageResource(R.drawable.arrow_down1);
                    mLvList.setEnabled(true);

                } else {
                    mLlMonth.setVisibility(View.VISIBLE);
                    mTvMonthText.setTextColor(getResources().getColor(R.color.event_btn_click));
                    mTvMonth.setTextColor(getResources().getColor(R.color.event_btn_click));
                    mIvMonthArrow.setImageResource(R.drawable.arrow_up1);
                    mLvList.setEnabled(false);
                }
                mLvYear.setVisibility(View.GONE);
                mTvYearText.setTextColor(getResources().getColor(R.color.schedule_content));
                mTvYear.setTextColor(getResources().getColor(R.color.schedule_content));
                mIvYearArrow.setImageResource(R.drawable.arrow_down1);
                break;
            case R.id.iv_weekly_detail_list_emotion:
                boolean visible = mEmotionLayout.getVisibility() == View.VISIBLE;
                if (visible) {
                    mIvEmotiom.setImageDrawable(getResources().getDrawable(R.drawable.selector_emotion_icon));
                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                } else {
                    mIvEmotiom.setImageDrawable(getResources().getDrawable(R.drawable.selector_keyboard_btn));
                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WeeklyDetailListActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                }
                mEmotionLayout.setVisibility(visible ? View.GONE : View.VISIBLE);
                break;
            case R.id.tv_weekly_detail_list_send:
                addCommentMsg(mSendMessage, commentWeeklyId);

                break;
            case R.id.et_weekly_detail_list_input:
                visible = (mEmotionLayout.getVisibility() == View.VISIBLE);
                mIvEmotiom.setImageDrawable(getResources().getDrawable(R.drawable.selector_emotion_icon));
                if (visible) {
                    mEmotionLayout.setVisibility(View.GONE);
                }
                break;
        }
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch (view.getId()) {
            case R.id.lv_weekly_detail_list_year_list:
                mLvYear.setVisibility(View.GONE);
                mTvYearText.setTextColor(getResources().getColor(R.color.schedule_content));
                mTvYear.setTextColor(getResources().getColor(R.color.schedule_content));
                mIvYearArrow.setImageResource(R.drawable.arrow_down1);
                break;
            case R.id.ll_weekly_detail_list_month_grid:
                mLlMonth.setVisibility(View.GONE);
                mTvMonthText.setTextColor(getResources().getColor(R.color.schedule_content));
                mTvMonth.setTextColor(getResources().getColor(R.color.schedule_content));
                mIvMonthArrow.setImageResource(R.drawable.arrow_down1);
                mLvList.setEnabled(true);
                break;

        }
        return false;
    }


    /**
     * 我的周报
     */
    private void getMyWeeklyList() {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_GROUP_ID, mGroupId));
        WeeklyMyListMsg weeklyMyListMsg = new WeeklyMyListMsg(mHandler.obtainMessage(GET_MY_WEEKLY_LIST), this, mGroupId, mAction);
        weeklyMyListMsg.mApi = AsynHttpClient.API_EVENT_WEEKLY_SELF;
        weeklyMyListMsg.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(weeklyMyListMsg);

    }

    /**
     * 第N周周报list
     */
    private void getNWeeklyList() {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_GROUP_ID, mGroupId));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_IDS, mWeeklyIds));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_WEEKLY_YEAR, getIntent().getStringExtra("year")));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_WEEKLY_MONTH, getIntent().getStringExtra("month")));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_WEEK_COUNT, getIntent().getStringExtra("weekCount")));

        WeeklyMyListMsg weeklyMyListMsg = new WeeklyMyListMsg(mHandler.obtainMessage(GET_MY_WEEKLY_LIST), this, mGroupId, mAction,getIntent().getStringExtra("year"),getIntent().getStringExtra("month"),getIntent().getStringExtra("weekCount"));
        weeklyMyListMsg.mApi = AsynHttpClient.API_EVENT_WEEKLY_LIST_WEEK;
        weeklyMyListMsg.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(weeklyMyListMsg);

    }

    /**
     * 发表评论
     */
    private void addCommentMsg(String comment, String weeklyId) {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_WEEKLY_ID, weeklyId));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_CONTENT, comment));
        GetMsgHttpReceiver getMsgHttpReceiver = new GetMsgHttpReceiver(mHandler.obtainMessage(ADD_COMMENT_MSG));
        getMsgHttpReceiver.mApi = AsynHttpClient.API_EVENT_WEEKLY_COMMENT;
        getMsgHttpReceiver.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(getMsgHttpReceiver);
    }


    public void showDeleteDialog(final String weeklyId, int position) {
        mPosition = position;
        String okText = this.getString(R.string.label_btn_delete);
        String cancelText = this.getString(R.string.cancel);
        mDialogUtil.titleDeleteMsgStyle(okText, cancelText, "将周报从服务器中删除，且该周报不可找回，是否确认删除");
        mDialogUtil.setOnDialogListener(new AllDialogUtil.DialogOnClickListener() {
            @Override
            public void onConfirmClick(Dialog lDialog) {
                httpReqDlgShow();
                deleteWeeklyMsg(weeklyId);
                lDialog.dismiss();
            }

            @Override
            public void onCancelClick(Dialog lDialog) {
                lDialog.dismiss();
            }
        });
    }

    private void httpReqDlgShow() {
        if (mProgressDialog == null) {
            mProgressDialog = AllDialogUtil.getInstance(this).waitDialog();
//            mProgressDialog.setCancelable(false);
            mProgressDialog.show();
        }

    }

    private void httpReqDlgDismiss() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
    }

    public void deleteWeeklyMsg(String weeklyId) {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_WEEKLY_ID, weeklyId));
        GetMsgHttpReceiver getMsgHttpReceiver = new GetMsgHttpReceiver(mHandler.obtainMessage(DELETE_WEEKLY_MSG));
        getMsgHttpReceiver.mApi = AsynHttpClient.API_EVENT_WEEKLY_DELETE;
        getMsgHttpReceiver.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(getMsgHttpReceiver);
    }


    private void getFilterWeekly() {
        int type = 0;
        if (yearPostion != 0 && yearPostion != 1 && monthPosition == -1) {
            type = 0;
        } else if ((yearPostion == 0 || yearPostion == 1) && monthPosition == -1) {
            type = 1;
        } else if (yearPostion != 0 && yearPostion != 1 && monthPosition != -1) {
            type = 2;
        } else if ((yearPostion == 0 || yearPostion == 1) && monthPosition != -1) {
            type = 3;
        }

        // 0: 不限定年月条件   1：限定年份，不限定月份  2：限定月份，不限定年份  3：限定年份和月份
        dataBeans.clear();
        if (monthPosition % 2 == 0) {
            dataBeans = mCloudDBOperation.findWeeklyDetailListData(type, year[yearPostion].replace("年", ""), monthPosition / 2 + 1 + "", mAction, mGroupId,"0");
        } else {
            dataBeans = mCloudDBOperation.findWeeklyDetailListData(type, year[yearPostion].replace("年", ""), (monthPosition - 1) / 2 + 1 + 6 + "", mAction, mGroupId,"0");
        }
        adapter.bindData(dataBeans);
    }


    /**
     * 弹出回复框
     *
     * @param position
     */
    public void showBottomLayout(String weeklyId, int position) {
        mLlBottomLayout.setVisibility(View.VISIBLE);
        boolean visible = (mEmotionLayout.getVisibility() == View.VISIBLE);
        if (visible) {
            mIvEmotiom.setImageDrawable(getResources().getDrawable(R.drawable.selector_emotion_icon));
            mEmotionLayout.setVisibility(View.GONE);
        }
        ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

        mPosition = position;
        commentWeeklyId = weeklyId;
        mEtCommentEdit.setText("");
        mEtCommentEdit.requestFocus();
        mEtCommentEdit.setHint("发表评论");
    }

    public void ifShowPopBg(boolean flag) {
        if (flag) {
            mIvPopBg.setVisibility(View.VISIBLE);
        } else {
            mIvPopBg.setVisibility(View.GONE);
        }
    }


    TextWatcher mTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            mSendMessage = mEtCommentEdit.getText().toString().trim();
            if (!StringUtil.isEmpty(mSendMessage)) {
                mTvSend.setVisibility(View.VISIBLE);
            } else {
                mTvSend.setVisibility(View.GONE);
            }

        }
    };


    public void setNewMsg() {
        if (mUnReadCount == 0) {
            mRedDot.setVisibility(View.GONE);
        } else {
            mRedDot.setVisibility(View.VISIBLE);
            if (mUnReadCount > 0 && mUnReadCount < 10) {
                ViewGroup.LayoutParams linearParams = mRedDot.getLayoutParams();
                int pd = Constants.dip2px(WeeklyDetailListActivity.this, 16);
                linearParams.width = pd;
                linearParams.height = pd;
                mRedDot.setLayoutParams(linearParams);
                mRedDot.setBackgroundResource(R.drawable.unread_1);
                mRedDot.setGravity(Gravity.CENTER);
                mRedDot.setText(mUnReadCount + "");
            } else if (mUnReadCount >= 10 && mUnReadCount < 100) {
                ViewGroup.LayoutParams linearParams = mRedDot.getLayoutParams();
                int widthPx = Constants.dip2px(WeeklyDetailListActivity.this, 24);
                int heightPx = Constants.dip2px(WeeklyDetailListActivity.this, 16);
                linearParams.width = widthPx;
                linearParams.height = heightPx;
                mRedDot.setLayoutParams(linearParams);
                mRedDot.setBackgroundResource(R.drawable.unread_2);
                mRedDot.setText(mUnReadCount + "");
            } else if (mUnReadCount >= 100) {
                ViewGroup.LayoutParams linearParams = mRedDot.getLayoutParams();
                int widthPx = Constants.dip2px(WeeklyDetailListActivity.this, 34);
                int heightPx = Constants.dip2px(WeeklyDetailListActivity.this, 16);
                linearParams.width = widthPx;
                linearParams.height = heightPx;
                mRedDot.setLayoutParams(linearParams);
                mRedDot.setBackgroundResource(R.drawable.unread_3);
                mRedDot.setText("99+");
            }
        }
    }


}
